package com.jason.annotation;

import org.junit.Test;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method;

// 定义一个注解 @MyTaget
@Retention(RetentionPolicy.RUNTIME)
@interface MyTaget{};

/**
 * @Author: Jason
 * @Date: 16/6/8
 * @Time: 11:02
 */
public class RetentionTest {


    @Test
    public void test1() throws NoSuchMethodException {
        getName();

        Method method = RetentionTest.class.getMethod("getName", null);
        Method method1 = RetentionTest.class.getMethod("setName", null);
        // 如果getName方法存在@MyTaget注解则为true
        System.out.println(method.isAnnotationPresent(MyTaget.class));
        System.out.println(method1.isAnnotationPresent(MyTaget.class));


    }


    @MyTaget
    public void getName() {

        System.out.println("retention   test    getName");

    }

    public void setName() {
        System.out.println("test--------setName");
    }
}
